//
//  NYUploadImageRequest.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2017/11/5.
//  Copyright © 2017年 niuwaketang. All rights reserved.
//

#import "NYUploadImageRequest.h"
#import "RMUUid.h"
#import "NYSecurityTools.h"
@interface NYUploadImageRequest ()
@property(nonatomic, copy) NSURL *imgFileUrl;
@end
@implementation NYUploadImageRequest
- (instancetype)initWithImgFileUrl:(NSURL *)imgFileUrl
{
        NYUploadImageRequest *request = [[NYUploadImageRequest alloc] initWithParams:@{
//                                                                                       @"pic_file" : imgFileUrl.absoluteString.lastPathComponent.stringByDeletingPathExtension
                                                                                       }];
        request.imgFileUrl = imgFileUrl;
        
        NSAssert(imgFileUrl, @"imgFilePath 不能为空");
        request.constructingBodyBlock = ^(id<AFMultipartFormData>  _Nonnull formData) {
                NSError *error = nil;
                [formData appendPartWithFileURL:imgFileUrl name:@"pic_file" error:&error];
                if (error) {
                        NSLogError(@"upload image appendPartWithFileURL error %@",error);
                }
        };
        return request;
}
- (NetworkRequestType)requestType
{
        return NetwrokRequestTypePOST;
}
- (BOOL)needSign
{
        return NO;
}
- (BOOL)blockSelfUntilDone
{
        return YES;
}
- (NSString *)url
{
        return @"/member/portrait";
}
- (NSMutableDictionary *)defaultParams
{
        return @{
                 kRequestKeyUser_ID : NOT_NULL_STRING_DEFAULT_EMPTY(NYUserManager.user_id),
                 kRequestKeyLoginCode : NOT_NULL_STRING_DEFAULT_EMPTY(NYUserManager.logincode),
                 }.mutableCopy;
}

@end
